/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package com.thingsgrid.notice.repository;

import com.thingsgrid.notice.entity.NoticeEntiy;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;

import java.util.List;

/**
 * 服务类
 *
 * @author MQ
 */
public interface INoticeRepository extends MongoRepository<NoticeEntiy, String> {
    /**
     * 分页查询
     * @param noticeEntiy
     * @param ids
     * @param page
     * @return
     */
    @Query("{ 'message_type':?#{[0].messageType},id:{$in:?#{[1]}}," +
            "$or:[{'title': ?#{ [0].title.length() == 0  ? {$exists:true} : {$regex: [0].title} }}],$or:[{"+
          //  "$or:[{'title': ?#{ ([0].title == null) || ([0].title.length() == 0)  ? {$exists:true} : {$regex: [0].title} }}],$or:[{"+
            "'content': ?#{ ([0].content == null) || ([0].content.length() == 0)  ? {$exists:true} : {$regex: [0].content } }}]}")
    Page<NoticeEntiy> page(NoticeEntiy noticeEntiy,List<String> ids,Pageable page);

	@Query("{id:{$in:?#{[1]}}," +
		"$or:[{'title': ?#{ [0].title.length() == 0  ? {$exists:true} : {$regex: [0].title } }}],$or:[{"+
		//"$or:[{'title': ?#{ ([0].title == null) || ([0].title.length() == 0)  ? {$exists:true} : {$regex: [0].title } }}],$or:[{"+
		"'content': ?#{ ([0].content == null) || ([0].content.length() == 0)  ? {$exists:true} : {$regex: [0].content } }}]}")
	Page<NoticeEntiy> page1(NoticeEntiy noticeEntiy,List<String> ids,Pageable page);

}


